import dayjs from 'dayjs'
export default {
	data() {
		return {
			IMG_URL: 'https://nuozhong.oss-cn-beijing.aliyuncs.com/',
			isPc: uni.getSystemInfoSync().model == "PC"
		}
	},
	methods: {
		dateFormat(timestamp, format = 'YYYY-MM-DD HH:mm') {
			if (!timestamp) return ''
			return dayjs(timestamp).format(format)
		},
		openerEvent(entity) {
			// #ifdef MP-WEIXIN
			const eventChannel = this.getOpenerEventChannel()
			// #endif
			// #ifdef H5
			const eventChannel = this.getOpenerEventChannel()
			// #endif
			// #ifdef APP-PLUS
			const eventChannel = this.$scope.eventChannel
			// #endif
			if (entity == 'onLoad') return eventChannel
			if (eventChannel && eventChannel.emit) {
				eventChannel.emit('backEvent', entity || null);
			}
		},
		navigateBack(url, page = 1, delta = 1) {
			const pages = getCurrentPages()
			console.log(pages.length)
			if (pages.length > delta) return uni.navigateBack({
				delta
			})
			uni.navigateTo({
				url: url
			})
		},
		navigateBack(url, page = 1, delta = 1) {
			const pages = getCurrentPages()
			if (pages.length > delta) return uni.navigateBack({
				delta
			})
			const tabBarUrl = [
				'/pages/index/index',
				'/pages/project/project',
				'/pages/transaction/transaction',
				'/pages/mine/mine'
			]
			if (tabBarUrl.some(item => item == url)) {
				return uni.switchTab({
					url: url
				})
			}
			uni.navigateTo({
				url: url
			})
		},
		copyEvent(str){
			if (!str) return
			uni.setClipboardData({
				data: str,
			})
		}
	}
}